let ApigwClient = require('./indexPost');

class KingdeeStoreGroup {

    /**
     * 构造器
     */
    constructor(clientID, clientSecret, appToken) {
        this.clientID = clientID;
        this.clientSecret = clientSecret;
        this.appToken = appToken;
    }

    /**
     * 增加仓库分类
     */
    async storeGroup(data = {}, params = {}) {
        let list;
        try {
            let requestSDK = new ApigwClient(this.clientID, this.clientSecret, this.appToken);
            const api = 'https://api.kingdee.com/jdy/v2/bd/store_group';
            const resp = await requestSDK.request({
                url: api,
                method: 'post',
                params,
                data
            });
            list = resp.data.data;
        } catch (e) {
            console.error('增加仓库分类', e);
            throw e;
        }
        return list;
    }

    /**
     * 仓库分类列表
     */
    async getStoreGroup(data = {}, params = {}) {
        let list;
        try {
            let requestSDK = new ApigwClient(this.clientID, this.clientSecret, this.appToken);
            const api = 'https://api.kingdee.com/jdy/v2/bd/store_group';
            const resp = await requestSDK.request({
                url: api,
                method: 'get',
                params,
                data
            });
            list = resp.data.data;
        } catch (e) {
            console.error('增加仓库分类', e);
            throw e;
        }
        return list;
    }
}

module.exports = KingdeeStoreGroup;
